﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.XPath;
using System.Xml;
using System.IO;

namespace ArticleUploadBatch.WinUI.Configs
{
    public class AppConfigXml
    {
        public static string _xmlFilePath =Path.Combine(Environment.CurrentDirectory, "CfgFiles/app_config.xml");
        public static string GetAppSettingValue(string key)
        {          
            var xmlDoc = new XmlDocument();
            xmlDoc.Load(_xmlFilePath);
            XmlNodeList xmlNodeList = xmlDoc.SelectNodes("//appSettings/add");
            foreach (XmlNode item in xmlNodeList)
            {
                if (item.Attributes["key"].Value ==key)
                {
                    return item.Attributes["value"].Value;
                }
            }
            return "";
        }

        public static string GetAttributeValue(string xpath, string attributeName)
        {
            var xmlDoc = new XmlDocument();
            xmlDoc.Load(_xmlFilePath);
            var node = xmlDoc.SelectSingleNode(xpath);
            return node?.Attributes?[attributeName]?.Value;
        }
    }
}
